﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _003
{
    /// <summary>
    /// C#属性——访问器案例
    /// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            //创建一个新的Student对象
            Student s = new Student();
            //设置Student的code、name和age
            s.Code = "001";
            s.Name = "Zar";
            s.Age = 30;
            Console.WriteLine("学生信息：{0}",s);
            //增加年龄
            s.Age += 1;
            Console.WriteLine("学生信息：{0}",s);
            Console.ReadKey();
        }
    }
    public abstract class Person
    {
        public abstract string Name
        {
            get;
            set;
        }
        public abstract int Age
        {
            get;
            set;
        }
    }
    class Student
    {
        private string code = "N.A";
        private string name = "not know";
        private int age = 0;
        //声明类型为String的Code属性
        public string Code
        {
            get
            {
                return code;
            }
            set
            {
                code = value;
            }
        }
        //声明类型为String的Name属性
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        //声明类型为int的Age属性
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }
        public override string ToString()//重写
        {
            return "编号="+Code + ",姓名=" + Name + ",年龄=" + Age;
        }
    }
}
